/*
 *------------------------------------------------------------------------------
 * @File      :    ei_mai_aenc_define.h
 * @Date      :    2021-4-8
 * @Author    :    lomboswer <lomboswer@lombotech.com>
 * @Brief     :    Media Interface for MADP(Media Development Platform).
 *
 * Copyright (C) 2020-2021, LomboTech Co.Ltd. All rights reserved.
 *------------------------------------------------------------------------------
 */

#ifndef __EI_MAI_AENC_DEFINE_H__
#define __EI_MAI_AENC_DEFINE_H__

#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif

#include "ei_mai_comm_define.h"

#define EI_AENC_MAX_CHN_NUM  2

#define AENC_CHN_REGISTER_CALLBACK_MAX_COUNT  5

typedef enum eiMADP_EN_AENC_ERR_CODE_E
{
    MADP_AENC_ERR_ENCODER_ERR     = 64 ,
} EI_MADP_EN_AENC_ERR_CODE_E;

#define EI_ERR_MAI_AENC_HANDLE_ILLEGAL                EI_MADP_DEF_ERR(EI_ID_AENC,MADP_EN_ERR_LEVEL_ERROR,MADP_EN_ERR_INVALID_CHNID)
#define EI_ERR_MAI_AENC_ILLEGAL_PARAM                 EI_MADP_DEF_ERR(EI_ID_AENC,MADP_EN_ERR_LEVEL_ERROR,MADP_EN_ERR_ILLEGAL_PARAM)
#define EI_ERR_MAI_AENC_EXIST                         EI_MADP_DEF_ERR(EI_ID_AENC,MADP_EN_ERR_LEVEL_ERROR,MADP_EN_ERR_EXIST)
#define EI_ERR_MAI_AENC_UNEXIST                       EI_MADP_DEF_ERR(EI_ID_AENC,MADP_EN_ERR_LEVEL_ERROR,MADP_EN_ERR_UNEXIST)
#define EI_ERR_MAI_AENC_NULL_PTR                      EI_MADP_DEF_ERR(EI_ID_AENC,MADP_EN_ERR_LEVEL_ERROR,MADP_EN_ERR_NULL_PTR)
#define EI_ERR_MAI_AENC_NOT_PERM                      EI_MADP_DEF_ERR(EI_ID_AENC,MADP_EN_ERR_LEVEL_ERROR,MADP_EN_ERR_NOT_PERM)
#define EI_ERR_MAI_AENC_NOMEM                         EI_MADP_DEF_ERR(EI_ID_AENC,MADP_EN_ERR_LEVEL_ERROR,MADP_EN_ERR_NOMEM)
#define EI_ERR_MAI_AENC_NOT_INITED                    EI_MADP_DEF_ERR(EI_ID_AENC,MADP_EN_ERR_LEVEL_ERROR,MADP_EN_ERR_SYS_NOTREADY)
#define EI_ERR_MAI_AENC_BUF_EMPTY                     EI_MADP_DEF_ERR(EI_ID_AENC,MADP_EN_ERR_LEVEL_ERROR,MADP_EN_ERR_BUF_EMPTY)
#define EI_ERR_MAI_AENC_ENCODER_ERR                   EI_MADP_DEF_ERR(EI_ID_AENC,MADP_EN_ERR_LEVEL_ERROR,MADP_AENC_ERR_ENCODER_ERR)

#define EI_MADP_AACLD_SAMPLES_PER_FRAME         512
#define EI_MADP_AACLC_SAMPLES_PER_FRAME         1024
#define EI_MADP_AACPLUS_SAMPLES_PER_FRAME       2048

#define MAX_AAC_MAINBUF_SIZE    768*2

typedef enum eiMADP_AAC_TYPE_E {
    EI_MADP_AAC_TYPE_AACLC      = 0,            /* AAC LC */
    EI_MADP_AAC_TYPE_EAAC       = 1,            /* eAAC  (HEAAC or AAC+  or aacPlusV1) */
    EI_MADP_AAC_TYPE_EAACPLUS   = 2,            /* eAAC+ (AAC++ or aacPlusV2) */
    EI_MADP_AAC_TYPE_AACLD      = 3,
    EI_MADP_AAC_TYPE_AACELD     = 4,
    EI_MADP_AAC_TYPE_BUTT,
} EI_MADP_AAC_TYPE_E;

typedef enum eiMADP_AAC_BPS_E {
    EI_MADP_AAC_BPS_8K      = 8000,
    EI_MADP_AAC_BPS_16K     = 16000,
    EI_MADP_AAC_BPS_22K     = 22000,
    EI_MADP_AAC_BPS_24K     = 24000,
    EI_MADP_AAC_BPS_32K     = 32000,
    EI_MADP_AAC_BPS_48K     = 48000,
    EI_MADP_AAC_BPS_64K     = 64000,
    EI_MADP_AAC_BPS_96K     = 96000,
    EI_MADP_AAC_BPS_128K    = 128000,
    EI_MADP_AAC_BPS_256K    = 256000,
    EI_MADP_AAC_BPS_320K    = 320000,
    EI_MADP_AAC_BPS_BUTT
} EI_MADP_AAC_BPS_E;

typedef enum eiMADP_AAC_TRANS_TYPE_E {
    EI_MADP_AAC_TRANS_TYPE_ADTS = 0,
    EI_MADP_AAC_TRANS_TYPE_LOAS = 1,
    EI_MADP_AAC_TRANS_TYPE_LATM_MCP1 = 2,
    EI_MADP_AAC_TRANS_TYPE_BUTT
} EI_MADP_AAC_TRANS_TYPE_E;


typedef struct eiMADP_AAC_FRAME_INFO_S {
    EI_S32 s32Samplerate;               /* sample rate*/
    EI_S32 s32BitRate;                  /* bitrate */
    EI_S32 s32Profile;                  /* profile*/
    EI_S32 s32TnsUsed;                  /* TNS Tools*/
    EI_S32 s32PnsUsed;                  /* PNS Tools*/
} EI_MADP_AAC_FRAME_INFO_S;

/*
    AAC Commendatory Parameter:
    Sampling Rate(HZ)    LC BitRate(Kbit/s)    EAAC BitRate (Kbit/s)    EAAC+ BitRate (Kbit/s)
    48000                128                    48                        32,24
    44100                128                    48                        32,24
    32000                96                     22                        16
    24000                64
    22050                64
    16000                48
*/

typedef struct eiMADP_AENC_ATTR_AAC_S {
    EI_MADP_AAC_TYPE_E          enAACType;   /* AAC profile type */
    EI_MADP_AAC_BPS_E           enBitRate;   /* AAC bitrate (LC:16~320, EAAC:24~128, EAAC+:16~64, AACLD:16~320, AACELD:32~320)*/
    EI_MADP_AUDIO_SAMPLE_RATE_E enSmpRate;   /* AAC sample rate (LC:8~48, EAAC:16~48, EAAC+:16~48, AACLD:8~48, AACELD:8~48)*/
    EI_MADP_AUDIO_BITWIDTH_E   enBitWidth;   /* AAC bit width (only support 16bit)*/
    EI_MADP_AUDIO_SOUND_MODE_E  enSoundMode; /* sound mode of inferent audio frame */
    EI_MADP_AAC_TRANS_TYPE_E    enTransType;

    EI_S16              s16BandWidth;        /* targeted audio bandwidth in Hz (0 or 1000~enSmpRate/2), the default is 0*/

} EI_MADP_AENC_ATTR_AAC_S;

typedef struct eiMADP_AENC_ATTR_S
{
    EI_MADP_AUDIO_FORMAT_E enAencFormat;
    EI_U32 u32PtNumPerFrm;
    EI_VOID *pValue;
    EI_U32 u32Len;
    EI_MADP_AUDIO_SAMPLE_RATE_E enSampleRate;
} EI_MADP_AENC_ATTR_S;

typedef struct eiMADP_AENC_STREAM_S
{
    EI_U8* pu8Addr;
    EI_U32 u32PhyAddr;
    EI_U32 u32Len;
    EI_U64 u64TimeStamp;
    EI_U32 u32Seq;
} EI_MADP_AENC_STREAM_S;

typedef EI_S32 (*PFN_AENC_DataProc)(EI_HANDLE AencHdl,
        EI_MADP_AENC_STREAM_S* pAStreamData, EI_VOID *pPrivateData);

typedef struct eiAENC_CALLBACK_S
{
    PFN_AENC_DataProc pfnDataCB;
    EI_VOID *pPrivateData;
} EI_AENC_CALLBACK_S;

typedef struct eiMADP_AENC_ENCODER_S
{
    EI_MADP_AUDIO_FORMAT_E  enType;
    EI_U32          u32MaxFrmLen;
    EI_CHAR         aszName[16]; /* encoder type,be used to print proc information */
    EI_S32          (*pfnOpenEncoder)(EI_VOID *pEncoderAttr, EI_VOID **ppEncoder); /* pEncoder is the handle to control the encoder */
    EI_S32          (*pfnEncodeFrm)(EI_VOID *pEncoder, const EI_MADP_AUDIO_FRAME_S *pstData,
                        EI_U8 *pu8Outbuf,EI_U32 *pu32OutLen);
    EI_S32          (*pfnCloseEncoder)(EI_VOID *pEncoder);
} EI_MADP_AENC_ENCODER_S;

#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif

#endif
